package com.lpf.rsa;

import javax.crypto.Cipher;

/**
 * 功能描述：非对称密钥加解密示例
 */
public class Test002 {

    public static void main(String[] args) {

        // 1、生成(公钥和私钥)密钥对
        RSAUtil.generateKey();
        System.out.println("公钥:" + RSAUtil.publicKey);
        System.out.println("私钥:" + RSAUtil.privateKey);

        System.out.println("----------公钥加密私钥解密-------------");

        // 2、使用公钥加密
        String textStr = "yushengjun";
        String encryptByPublic = RSAUtil.encryptByPublicKey(textStr, RSAUtil.publicKey, Cipher.ENCRYPT_MODE);
        System.out.println("公钥加密:" + encryptByPublic);

        // 3、私钥解密
        String text = RSAUtil.encryptByPrivateKey(encryptByPublic, RSAUtil.privateKey, Cipher.DECRYPT_MODE);
        System.out.println("私钥解密:" + text);
    }

}
